package com.example.plcopne.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.ToastUtils
import com.example.plcopne.R
import kotlinx.android.synthetic.main.activity_top_bar_base.*

abstract class BaseActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_top_bar_base)



        setSupportActionBar(toolbar);
        supportActionBar?.setDisplayShowTitleEnabled(false);

        LayoutInflater.from(this).inflate(getContentView(), view_content);
        init(savedInstanceState)



        supportActionBar?.apply {
            //左侧添加一个默认的返回图标
            setDisplayHomeAsUpEnabled(true)
            //设置返回键可用
            setHomeButtonEnabled(true);
        }

    }

    abstract fun getContentView(): Int
    abstract fun init(savedInstanceState: Bundle?)


    fun settitle(title: String?) {
        tv_title.text = title?.toString() ?: ""

    }


    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        //Toolbar的事件---返回
        if (item.itemId == android.R.id.home) {
            finish()
        }
        return super.onOptionsItemSelected(item)
    }


    fun showToast(msg: String) {
        ToastUtils.showShort(msg)
    }

}